//
//  NewsTableViewCell.m
//  必争医疗
//
//  Created by 付正 on 14-11-20.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NewsTableViewCell.h"
#import "NewsModel.h"
#import "UIImageView+WebCache.h"
@implementation NewsTableViewCell
- (void)dealloc
{
    [_model release];
    [_image release];
    [_titleLabel release];
    [_typeAndTime release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.image = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_image];
        [_image release];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel sizeToFit];
        [_titleLabel setNumberOfLines:0];
        [_titleLabel release];
        
        self.typeAndTime = [[UILabel alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_typeAndTime];
        [_typeAndTime sizeToFit];
        [_typeAndTime release];
        
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.image setFrame:CGRectMake(0, 0, 100, 100)];
    [self.titleLabel setFrame:CGRectMake(120, 0, 200, 60)];
    [self.typeAndTime setFrame:CGRectMake(120, 70, 200, 30)];
    
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{

    if ([keyPath isEqualToString:@"model"]) {
        [self.image setImageWithURL:[NSURL URLWithString:self.model.image]];
        self.titleLabel.text = self.model.title;
        self.typeAndTime.text = [NSString stringWithFormat:@"%@  %@", self.model.news_type_txt, self.model.date];
    }
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
